/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.cezary.butler.walili.client.mime;

import java.net.URLConnection;
import java.util.concurrent.Callable;

/**
 *
 * @author Czarek
 */
public abstract class MimeTypeAction implements Callable<Boolean> {

    private final URLConnection connection;
    private final Runnable callback;
    
    public MimeTypeAction() {
        this(null);
    }

    public MimeTypeAction(URLConnection connection, Runnable callback) {
        this.connection = connection;
        this.callback = callback;
    }
    
    

    public MimeTypeAction(URLConnection connection) {
        this(connection,null);
    }       

    public abstract boolean process(URLConnection connection);

    @Override
    public Boolean call() throws Exception {
        assert(connection!=null) : "This instance was constructed uncallable";
        final boolean result= process(connection);
        if(callback!=null)
            callback.run();
        return result;
    }
    
}
